/*
	Andrew Q. Philips
	7/3/19
	replication files for "Just in time: Political policy cycles of land reform" Forthcoming at Politics
	
	--Aggregate data analysis portion
	
*/

use "aggregate_analysis.dta", clear
version 12.1
set seed 20950192
xtset


* Fig 1b (Fig 1a done by hand): -----------------------------------
preserve 
drop if year<1957
drop if year>1992
collapse (sum) clr1 clr2 clr3 clr4, by(year)
twoway line clr1 year, lwidth(medthick) lcolor(black) || line clr2 year, lwidth(medthick) lcolor(black) || line clr3 year, lwidth(medthick) lcolor(black) || line clr4 year, lwidth(medthick) lcolor(black) legend(order(1 "Tenancy Reform" 2 "Intermediary Abolished" 3 "Landholding Ceilings" 4 "Landholding Consolidation"))	///
 note("Source: Indian States EOPP Database", span) scheme(s2mono) graphregion( color(white) )
graph export "cum_reforms.eps", as(eps) preview(off) replace
restore
* -----------------------------------------------------------------

* Figure 3 --------------------------------------------------------
eststo clear
eststo: xtreg landref f4elecdum f3elecdum f2elecdum f1elecdum elecdum i.year, fe robust
gen pred = .
margins , at(f4elecdum = 1 f3elecdum = 0 f2elecdum = 0 f1elecdum = 0 elecdum = 0) atmeans
mat temp = r(table)
mat list temp
local pred = temp[1,1]
* store:
replace pred = `pred' in 1
margins , at(f4elecdum = 0 f3elecdum = 1 f2elecdum = 0 f1elecdum = 0 elecdum = 0) atmeans
mat temp = r(table)
mat list temp
local pred = temp[1,1]
* store:
replace pred = `pred' in 2
margins , at(f4elecdum = 0 f3elecdum = 0 f2elecdum = 1 f1elecdum = 0 elecdum = 0) atmeans
mat temp = r(table)
mat list temp
local pred = temp[1,1]
* store:
replace pred = `pred' in 3
margins , at(f4elecdum = 0 f3elecdum = 0 f2elecdum = 0 f1elecdum = 1 elecdum = 0) atmeans
mat temp = r(table)
mat list temp
local pred = temp[1,1]
* store:
replace pred = `pred' in 4
margins , at(f4elecdum = 0 f3elecdum = 0 f2elecdum = 0 f1elecdum = 0 elecdum = 1) atmeans
mat temp = r(table)
mat list temp
local pred = temp[1,1]
* store:
replace pred = `pred' in 5
gen counter = _n
replace counter = . if counter > 5
twoway scatter pred counter, msymbol(O) mcolor(black) xlabel(1 "t-4" 2 "t-3" 3 "t-2" 4 "t-1" 5 "Election") xtitle("Years Before Election")  ylabel(0(.05).2) yscale(range(0(.05).2)) ytitle("Pr(Land Reform)")
graph export "simplepredictions.pdf", as(pdf) replace
* -----------------------------------------------------------------



*	----------------------------------------------------------------
/*				Table 1	---------------------------------------------	*/
eststo clear
qui xtlogit landref f1elecdum elecdum onep_dom zbot50_ ztop10_ eff_parties i.leftist##i.f1elecdum i.cong##i.f1elecdum, fe 
keep if e(sample)

* Baseline model
* test that the coeficents are distinct across elections:
eststo: xtlogit landref i.f1elecdum i.elecdum onep_dom multp_leftcenright twop_leftcenter twop_centerright noland i.year, fe
* test change in probability
margins , at(f1elecdum = (0 1) elecdum = 0) atmeans
margins , dydx(f1elecdum) at( elecdum = 0) atmeans
	
* Alternative Ideology coding
eststo: xtlogit landref f1elecdum elecdum onep_dom i.leftist i.cong noland i.year, fe
margins , at(leftist = (0 1) cong = 0) atmeans
margins , dydx(leftist) at( cong = 0) atmeans

* With EFF
eststo: xtlogit landref f1elecdum elecdum onep_dom leftist cong noland eff_parties i.year, fe

/* w/ inclusion of hectares under cultivation, no land*/
eststo: xtlogit landref f1elecdum elecdum onep_dom leftist cong bot50_ top10_ eff_parties i.year, fe

 esttab using table1.tex, replace se(2) star(* 0.10 ** 0.05 *** 0.01) sca("N Obs." "N_g States" "ll Log Lik." "chi2 $\chi^2$" "chi2_c Prob $ > \chi^2$" ) title( Evidence for Political Policy Cycles) addn(Logit with standard errors in parentheses. Two-tail tests presented despite directional hypotheses.) b(2)
*	----------------------------------------------------------------
